#ifndef DBHANDLER_H
#define DBHANDLER_H
#include <sqlite3.h>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;
//sqlite3_exec(sqlite3*, const char* sql, sqlite3_callback,void *data, char **errmsg);
//定义函数指针，之后定义回调函数有用
// * typedef int (*sqlite3_callback)(
//void*,    /* Data provided in the 4th argument of sqlite3_exec()
//int,      /* The number of columns in row
//char**,   /* An array of strings representing fields in the row
//char**    /* An array of strings representing column names
//);
//***/

class DbHandler{
protected:
    char dbpath[100] = "";
    sqlite3 *sql = nullptr;
    int InsertTableItem(const char *sql_lan);
    void CreateTable(const char *sql_lan);

public:
    bool SetDbPath(const char *str);
    bool OpenDb();

    void CloseDb();
    void DeleteTableItem(string table, string delete_item);
    void UpdateTableItem(string table, string set_item, string where);
    int SelectTableItem(string table, string item, string condition, int (*callback)(void*,int,char**, char**) , void* data);
};
#endif // DBHANDLER_H
